package files_controller_with_factory;
import java.io.*;
import org.apache.log4j.Logger;

public class DirCommandExecutor implements ICommandExecutor{
	private static final Logger cont_log = Logger.getLogger("control");
	
	public void execute(String string){
		String[] str_mas = string.split(" ");
		String path = str_mas[1];
		File folder = new File(path);
		if(!folder.exists()){
			cont_log.warn("Directory not found: " + path);
		} else{
			File[] list = folder.listFiles();
			System.out.println("Content of current directory...");
			for(File file : list){
				if(file.isDirectory()){
					cont_log.info("<dir> " + file.getName());
				} else if (file.isFile()){
					cont_log.info("<file> " + file.getName());
				}
			}
		}
	}
	
	private static DirCommandExecutor instance;
	private DirCommandExecutor(){		
	}
	public static ICommandExecutor getInstance(){
		if(instance==null){
			instance = new DirCommandExecutor();
		}
		return instance;
	}
}

